clc 
clear all

% ???????????????????????????????????????????
% ???????
%% ????
changdu = 500;                                                    %??
kuandu = 500;                                                     %??
jiaoyoufanwei =10;                                                %????
pengyoushu =60;                                                   %???

pingjunzhixindu = 0.5005;                                          %?????
zheangtai = 1/6;                                                  %

tuidonglv = 0.3;                                                  %?????
zhixinfazhi = 0.2;                                                %????

fankang1 = 0.1;
fankang2 = 0.1;

%% ???????????
history1 = 0;
history2 = 0;

%% ?????????

% ??????????
[frends] = jianliwangluo( changdu,kuandu,jiaoyoufanwei,pengyoushu );
% ??????????????????????
zhixindu= jianlizhixinjuzhen( pingjunzhixindu,zheangtai, changdu,kuandu);

% ?????????????????
% ????????????
net1 = zeros(changdu,kuandu);net2 = zeros(changdu,kuandu);
% ????
net1 = meitituidong(zhixindu,net1,1,1,500,500,tuidonglv,1);
net2 = meitituidong(zhixindu,net2,1,1,500,500,tuidonglv,2);

% ????
showpic;
% ????
newcbqk = jilushuju(net1,net2,changdu,kuandu);

%% ?????

% ??????????
count = 1;
% ??????????
oldcbqk = [-1 -1];

Adown = 0;
Bdown = 0;
blockchangdu = 10;
blockkuandu = blockchangdu;
side = 1;

for loop = 1:100
% ????????
    
    % ???????
    jilu(count,:) = newcbqk;
    % imwrite(PP,[num2str(count),'.jpg']);% ????
    % ????????????????
    
    [net1, net2] = renjichuanbo2(changdu,kuandu,jiaoyoufanwei,frends, pengyoushu, net1,net2, fankang1, fankang2,zhixinfazhi,zhixindu,Adown,Bdown);
    
    out{loop} = importantpoint(changdu, kuandu,jiaoyoufanwei,frends,pengyoushu, net1, net2, fankang1, fankang2,zhixinfazhi,zhixindu,Adown,Bdown,blockchangdu,blockkuandu,side);

    % ??A????B?????????
    if newcbqk(1) < oldcbqk(1)
        Adown = 1;
    else
        Adown = 0;
    end
    if newcbqk(2) < oldcbqk(2)
        Bdown = 1;
    else
        Bdown = 0;
    end
    
    % ????? ??
    oldcbqk = newcbqk;
    % ??????
    newcbqk = jilushuju(net1,net2,changdu,kuandu);
    showpic;%
    
    
    count  = count +1
end

csvwrite('history1.csv',jilu)
% plot(history1)
% hold on 
% plot(history2)
% history1